package com.ruoyi.framework.task;

import com.ruoyi.framework.redis.RedisCache;
import com.ruoyi.project.system.domain.CustUser;
import com.ruoyi.project.system.domain.Tiaojian;
import com.ruoyi.project.system.service.ICustUserService;
import com.ruoyi.project.system.service.ITiaojianService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.*;

@Service
public class SearchReceive implements ApplicationListener<ContextRefreshedEvent> {
    @Autowired
    RedisCache redisCache;


    @Autowired
    RyTask ryTask;

    @Autowired
    ICustUserService custUserService;

    @Autowired
    ITiaojianService tiaojianService;


    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        if (contextRefreshedEvent.getApplicationContext().getParent() == null) {//保证只执行一次
            ryTask.initDate();
            ryTask.synchroRedis();



        }
    }


    public static void main(String[] ar){
       List<CustUser> list=new ArrayList<>();

       list.add(new CustUser("a",new BigDecimal(10)));
       list.add(new CustUser("b",new BigDecimal(8)));
       list.add(new CustUser("c",new BigDecimal(7)));

        Collections.sort(list, new Comparator<CustUser>(){
            @Override
            public int compare(CustUser o1, CustUser o2) {
                if(o1.getUser().getNum().doubleValue()<o2.getUser().getNum().doubleValue()){
                    return 1;
                }
                return -1;
            }
        });


        for(CustUser c:list){
            System.out.println(c.getUserName()+" v:"+c.getUser().getNum().doubleValue());
        }

    }


}
